package at.fhj.itm.jface;

import javax.xml.ws.Dispatch;

import org.eclipse.jface.viewers.ILabelProviderListener;
import org.eclipse.jface.viewers.ITableColorProvider;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Display;

import at.fhj.itm.refactor.report.ReportItem;
import at.fhj.itm.refactor.report.ReportSeverity;

public class ReportItemTableLabelProvider implements ITableLabelProvider,ITableColorProvider  {

	private final Color DEFAULT;
	private final Color WARNING;
	private final Color ERROR;
	private final Color REFACTORING_STEP;
	private static final int COL_TITLE = 0;
	private static final int COL_EXPLANATION = 1;
	
	public ReportItemTableLabelProvider(){
		Display display = Display.getCurrent();
		DEFAULT = display.getSystemColor(SWT.COLOR_LIST_FOREGROUND);
		WARNING = display.getSystemColor(SWT.COLOR_DARK_YELLOW);
		ERROR = display.getSystemColor(SWT.COLOR_RED);
		REFACTORING_STEP = display.getSystemColor(SWT.COLOR_DARK_BLUE);
		
	}
	
	
	@Override
	public void addListener(ILabelProviderListener listener) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void dispose() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public boolean isLabelProperty(Object element, String property) {
		return true;
	}

	@Override
	public void removeListener(ILabelProviderListener listener) {
		
		
	}

	@Override
	public Color getForeground(Object element, int columnIndex) {
		ReportItem item = (ReportItem) element;
		
		if(item.getServerity() == ReportSeverity.ERROR){
			return ERROR;
		}
		if(item.getServerity() == ReportSeverity.WARNING){
			return WARNING;
		}
		if(item.getServerity() == ReportSeverity.REFACTORING_STEP){
			return REFACTORING_STEP;
		}
		return DEFAULT;
	}

	@Override
	public Color getBackground(Object element, int columnIndex) {
		return null;
	}

	@Override
	public Image getColumnImage(Object element, int columnIndex) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String getColumnText(Object element, int columnIndex) {
		ReportItem item = (ReportItem) element;
		if(columnIndex == COL_TITLE){
			return item.getTitle();
		}
		else if(columnIndex == COL_EXPLANATION){
			return item.getExplanation();
		}
		return "";
	}

}
